我正在尝试使用excel删除word文档中所有区域的水印。我可以在Word中用VB完成这项工作,我已经将代码翻译到excel中,以便在word中完成。没有错误,但代码无法删除或移除水印。我相信一定有一些额外的链接到它的形状或位置,我需要参考,但我不知道它会丢失什么。 Word VBA中的工作代码使用了spShape.Visible = False,这在excel中没有做任何事情,我也尝试过spShape.Delete,但也没有用。 感谢任何帮助,以下是我的代码: 代码语言:javascript复制Sub AddRemoveWatermark()
'Word Variables
Dim wrdApplication As Word.Application
Dim wrdDocument As Word.Document
Dim wrdSection As Word.section
Dim wrdHeader As Word.HeaderFooter
Dim rngHeader As Word.Range
Dim spShape As Word.Shape
Dim strDocumentName As String
Dim strPath As String
Dim strBBPath As String
Dim lngCount As Long
Dim pHeaderType As Long
Dim strShapeName As String
' Open the file dialog
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Show
Set wrdApplication = New Word.Application
' Display paths of each file selected
For lngCount = 1 To .SelectedItems.Count
strPath = .SelectedItems(lngCount)
Set wrdDocument = wrdApplication.Documents.Open(strPath)
strDocumentName = wrdDocument.FullName 'Record the document name
wrdApplication.Templates.LoadBuildingBlocks
wrdApplication.Visible = True
'Address each section
For Each wrdSection In wrdDocument.Sections
With wrdSection
Set rngHeader = .Headers(wdHeaderFooterFirstPage).Range
For Each spShape In rngHeader.ShapeRange
strShapeName = spShape.Name
If InStr(strShapeName, "PowerPlusWaterMarkObject") > 0 Then
'spShape.Delete
spShape.Visible = msoFalse
End If
Next
Set rngHeader = .Headers(wdHeaderFooterPrimary).Range
For Each spShape In rngHeader.ShapeRange
strShapeName = spShape.Name
If InStr(strShapeName, "PowerPlusWaterMarkObject") > 0 Then
'spShape.Delete
spShape.Visible = msoFalse
End If
Next
End With
Next wrdSection
wrdDocument.SaveAs (wrdDocument.FullName)
wrdDocument.Close
Next lngCount
End With
wrdApplication.Quit
End Sub
|